package com.chub.study.modules.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author : chub
 * @version : V1.0.0
 * @file name      : MyMetaObjectHandler
 * @describe : TODO
 * @created on     : 2021-08-25 17:30
 * @last modified  : 2021-08-25 17:30
 * @module purpose : TODO
 */

//添加 @Component 注解，交给 Spring 去管理。
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "crtUser", String.class, "adminCRT");
        this.strictInsertFill(metaObject, "delFlag", Integer.class, 0);
        this.setFieldValByName("crtTime", new Date(), metaObject);
        this.setFieldValByName("uptTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "crtUser", String.class, "adminUPT");
        this.setFieldValByName("uptTime", new Date(), metaObject);
    }
 }
